package com.rchat.pocmini.media;

import com.airtalkee.sdk.AirtalkeeMediaVisualizer;
import com.airtalkee.sdk.OnMediaAudioVisualizerListener;

/**
 * Created by ljd on 2017/2/6.
 * <p>
 * 提供音频录音和播放的频谱数据
 */

public class PocMediaVisualizer implements PocMediaVisualizerInterface {

    private static AirtalkeeMediaVisualizer airtalkeeMediaVisualizer = AirtalkeeMediaVisualizer.getInstance();

    private static PocMediaVisualizer pocMediaVisualizer;

    private PocMediaVisualizer() {
    }

    /**
     * 获取AirtalkeeMediaVisualizer实例
     *
     * @return airtalkeeMediaVisualizer
     */
    public static PocMediaVisualizer getPocMediaVisualizerInstance() {
        if (pocMediaVisualizer == null) {
            pocMediaVisualizer = new PocMediaVisualizer();
        }
        return pocMediaVisualizer;
    }

    /**
     * 注册监听器，在录音和播放时返回音频频谱的事件，关心OnMediaAudioVisualizerListener事件的实例，均需要通过此接口注册，否则将收不到相应事件。
     *
     * @param listener 监听器
     */
    @Override
    public void setOnMediaAudioVisualzerListener(OnMediaAudioVisualizerListener listener) {
        airtalkeeMediaVisualizer.setOnMediaAudioVisualizerListener(listener);
    }

    /**
     * 设置音频频谱数
     *
     * @param spectrumNum 每次频谱刷新时提供的频谱数量
     */
    @Override
    public void setMediaAudioVisualizerSpectrumNumber(int spectrumNum) {
        airtalkeeMediaVisualizer.setMediaAudioVisualizerSpectrumNumber(spectrumNum);
    }

    /**
     * SDK频谱功能默认为关闭，需要通过此接口开启或关闭
     *
     * @param isValid
     */
    @Override
    public void setMediaAudioVisualizerValid(boolean isValid) {
        airtalkeeMediaVisualizer.setMediaAudioVisualizerValid(isValid);
    }

    /**
     * SDK频谱功能默认为关闭，需要通过此接口开启或关闭
     *
     * @param isPlayerValid
     * @param isRecorderValid
     */
    @Override
    public void setMediaAudioVisualizerValid(boolean isPlayerValid, boolean isRecorderValid) {
        airtalkeeMediaVisualizer.setMediaAudioVisualizerValid(isPlayerValid, isRecorderValid);
    }
}
